package tests;

import java.util.ArrayList;
import java.util.List;

import org.junit.After;
import org.junit.Before;

import android.test.AndroidTestCase;
import android.test.RenamingDelegatingContext;

import com.project.savelog.DataSource;
import com.project.savelog.Devices;
import com.project.savelog.Games;
import com.project.savelog.Saves;
import com.project.savelog.Systems;
import com.project.savelog.Themes;

/**
 * Title: DataSourceTest class for CSIS 343 Final Project 
 * Description: CS 343 Final Project - DataSourceTest This class will test the 
 * DataSource class that handle all of the local database calls
 * 
 * @author Erik Olson
 * @email erik.olson-5@my.uwrf.edu
 * @author Mike Harmon
 * @email michael.harmon@my.uwrf.edu
 * @author Jack Friermuth
 * @email jack.friermuth@my.uwrf.edu
 * @author Luke Vang
 * @email luke.vang@my.uwrf.edu
 * @author Casey Golla
 * @email casey.golla@my.uwrf.edu
 * @date December 4th 2012
 */
public class DataSourceTest extends AndroidTestCase {
	//Database fields
	private DataSource db;

	@Before
	public void setUp() throws Exception {
		//creating a database for testing
		RenamingDelegatingContext context = new RenamingDelegatingContext(getContext(), "test_");
		db = new com.project.savelog.DataSource( context );
		db.open();
	}

	@After
	public void tearDown() throws Exception {
		//closing the database
		db.removeAllEntries();
		db.close();
		db = null;
	}

	/**
	 * Tests that you can delete a save
	 * @Test
	 */
	public final void testDeleteSave() {
		//creating a save
		Saves save = db.createSave( 1, "MegaMan Save", "2013/11/29", "2013/11/29", "/home/mike", 1 );
		
		int delete_id = save.getSave_id();
		
		//deleting the new save
		db.deleteSave( delete_id );
		
		//making sure save is gone
		List<Saves> saves = db.getAllSaves();
		
		for (Saves temp_save : saves) {
			Integer temp_id = temp_save.getSave_id();
			assertFalse( temp_id.equals( delete_id ) );
		}
	}

	/**
	 * Tests that you can insert a save and get the inserted save back
	 * @Test
	 */
	public final void testCreateSave() {
		//creating a save
		Saves save = db.createSave( 1, "MegaMan Save", "2013/11/29", "2013/11/29", "/home/mike", 1 );
		
		//making sure save is in database
		Saves db_save = db.getSaveById( save.getSave_id() );
		assertEquals( save.getDev_id(), db_save.getDev_id() );
		assertEquals( save.getGame_id(), db_save.getGame_id() );
		assertEquals( save.getSave_date_created(), db_save.getSave_date_created() );
		assertEquals( save.getSave_date_logged(), db_save.getSave_date_logged() );
		assertEquals( save.getSave_descrip() , db_save.getSave_descrip() );
		assertEquals( save.getSave_id() , db_save.getSave_id() );
		assertEquals( save.getSave_src() , db_save.getSave_src() );
	}

	/**
	 * Tests that you can insert a save
	 * @Test
	 */
	public final void testInsertSave() {
		//creating a save
		db.insertSave( 1, "MegaMan Save", "2013/11/29", "2013/11/29", "/home/mike", 1 );
		
		//making sure save is in database 
		List<Saves> saves = db.getAllSaves();
		List<Saves> expected = new ArrayList<Saves>();
		expected.add( new Saves( 17, 1, "MegaMan Save", "2013/11/29", "2013/11/29", "/home/mike", 1 ) );
		
		assertEquals( saves.get( 0 ).getDev_id(), expected.get( 0 ).getDev_id() );
		assertEquals( saves.get( 0 ).getGame_id(), expected.get( 0 ).getGame_id() );
		assertEquals( saves.get( 0 ).getSave_date_created(), expected.get( 0 ).getSave_date_created() );
		assertEquals( saves.get( 0 ).getSave_date_logged(), expected.get( 0 ).getSave_date_logged() );
		assertEquals( saves.get( 0 ).getSave_descrip() , expected.get( 0 ).getSave_descrip() );
		assertEquals( saves.get( 0 ).getSave_id() , expected.get( 0 ).getSave_id() );
		assertEquals( saves.get( 0 ).getSave_src() , expected.get( 0 ).getSave_src() );
	}

	/**
	 * Tests that you can get a save by a save id
	 * @Test
	 */
	public final void testGetSaveById() {
		//creating a save 
		Saves save = db.createSave( 1, "MegaMan Save", "2013/11/29", "2013/11/29", "/home/mike", 1 );
		
		//making sure we can get the correct save back when we provide the save id
		Saves db_save = db.getSaveById( save.getSave_id() );
		assertEquals( save.getDev_id(), db_save.getDev_id() );
		assertEquals( save.getGame_id(), db_save.getGame_id() );
		assertEquals( save.getSave_date_created(), db_save.getSave_date_created() );
		assertEquals( save.getSave_date_logged(), db_save.getSave_date_logged() );
		assertEquals( save.getSave_descrip() , db_save.getSave_descrip() );
		assertEquals( save.getSave_id() , db_save.getSave_id() );
		assertEquals( save.getSave_src() , db_save.getSave_src() );
	}

	/**
	 * Tests that you can get all saves in the database
	 * @Test
	 */
	public final void testGetAllSaves() {
		//inserting some saves
		db.insertSave( 1, "MegaMan Save", "2013/11/29", "2013/11/29", "/home/mike", 1 );
		db.insertSave( 2, "Zelda Save", "2013/11/28", "2013/11/28", "/home/mike", 2 );
		db.insertSave( 3, "Mario Save", "2013/11/27", "2013/11/27", "/home/mike", 3 );
		
		//making sure we can get all of the saves 
		List<Saves> saves = db.getAllSaves();
		List<Saves> expected = new ArrayList<Saves>();
		
		expected.add( new Saves( 3, 1, "MegaMan Save", "2013/11/29", "2013/11/29", "/home/mike", 1 ) );
		expected.add( new Saves( 4, 2, "Zelda Save", "2013/11/28", "2013/11/28", "/home/mike", 2 ) );
		expected.add( new Saves( 5, 3, "Mario Save", "2013/11/27", "2013/11/27", "/home/mike", 3 ) );
		
		for( int i = 0 ; i < 3 ; i++ ) {
			assertEquals( saves.get( i ).getDev_id(), expected.get( i ).getDev_id() );
			assertEquals( saves.get( i ).getGame_id(), expected.get( i ).getGame_id() );
			assertEquals( saves.get( i ).getSave_date_created(), expected.get( i ).getSave_date_created() );
			assertEquals( saves.get( i ).getSave_date_logged(), expected.get( i ).getSave_date_logged() );
			assertEquals( saves.get( i ).getSave_descrip() , expected.get( i ).getSave_descrip() );
			assertEquals( saves.get( i ).getSave_id() , expected.get( i ).getSave_id() );
			assertEquals( saves.get( i ).getSave_src() , expected.get( i ).getSave_src() );
		}
	}

	/**
	 * Tests that you can delete a device
	 * @Test
	 */
	public final void testDeleteDevice() {
		//creating a device
		Devices device = db.createDevice( "My Tablet" );
		
		int delete_id = device.getDev_id();
		
		//deleting the new device
		db.deleteDevice( delete_id );
		
		//making sure device is gone
		List<Devices> devices = db.getAllDevices();
		
		for (Devices temp_device : devices) {
			Integer temp_id = temp_device.getDev_id();
			assertFalse( temp_id.equals( delete_id ) );
		}
	}

	/**
	 * Tests that you can insert a device and get the inserted device back
	 * @Test
	 */
	public final void testCreateDevice() {
		//creating a device
		Devices device = db.createDevice( "My Tablet" );
		
		//making sure device is in database
		Devices db_device = db.getDeviceById( device.getDev_id() );
		assertEquals( device.getDev_id(), db_device.getDev_id() );
		assertEquals( device.getDev_name() , db_device.getDev_name() );
	}

	/**
	 * Tests that you can insert a device
	 * @Test
	 */
	public final void testInsertDevice() {
		//inserting a device
		db.insertDevice( "My Tablet" );
		
		//making sure device is in database 
		List<Devices> devices = db.getAllDevices();
		List<Devices> expected = new ArrayList<Devices>();
		
		expected.add( new Devices( 7, "My Tablet" ) );
		
		assertEquals( devices.get( 0 ).getDev_id(), expected.get( 0 ).getDev_id() );
		assertEquals( devices.get( 0 ).getDev_name() , expected.get( 0 ).getDev_name() );
	}

	/**
	 * Tests that you can get a device by its device id
	 * @Test
	 */
	public final void testGetDeviceById() {
		//creating a device 
		Devices device = db.createDevice( "My Phone" );
		
		//making sure we can get the correct device back when we provide the device id
		Devices db_device = db.getDeviceById( device.getDev_id() );
		assertEquals( device.getDev_id(), db_device.getDev_id() );
		assertEquals( device.getDev_name() , db_device.getDev_name() );
	}

	/**
	 * Tests that you can get all devices in the database
	 * @Test
	 */
	public final void testGetAllDevices() {
		//inserting some devices
		db.insertDevice( "My Tablet1" );
		db.insertDevice( "My Tablet2" );
		db.insertDevice( "My Tablet3" );
		
		//making sure we can get all of the devices 
		List<Devices> devices = db.getAllDevices();
		List<Devices> expected = new ArrayList<Devices>();
		
		expected.add( new Devices( 3, "My Tablet1" ) );
		expected.add( new Devices( 4, "My Tablet2" ) );
		expected.add( new Devices( 5, "My Tablet3" ) );
		
		for( int i = 0 ; i < 3 ; i++ ) {
			assertEquals( devices.get( i ).getDev_id(), expected.get( i ).getDev_id() );
			assertEquals( devices.get( i ).getDev_name() , expected.get( i ).getDev_name() );
		}
	}

	/**
	 * Tests that you can delete a game
	 * @Test
	 */
	public final void testDeleteGame() {
		//creating a game
		Games game= db.creategame( "MegaMan", "/home/mike", 1, 1 );
		
		int delete_id = game.getGame_id();
		
		//deleting the new game
		db.deleteGame( delete_id );
		
		//making sure game is gone
		List<Games> games = db.getAllGames();
	
		for (Games temp_game : games) {
			Integer temp_id = temp_game.getGame_id();
			assertFalse( temp_id.equals( delete_id ) );
		}
	}

	/**
	 * Tests that you an insert a game and get the inserted game back
	 * @Test
	 */
	public final void testCreategame() {
		//creating a game
		Games game= db.creategame( "MegaMan", "/home/mike", 1, 1 );
		
		//making sure game is in database
		Games db_game = db.getGameById( game.getGame_id() );
		assertEquals( game.getDev_id(), db_game.getDev_id() );
		assertEquals( game.getGame_cover(), db_game.getGame_cover() );
		assertEquals( game.getGame_id(), db_game.getGame_id() );
		assertEquals( game.getGame_title(), db_game.getGame_title() );
		assertEquals( game.getSys_id(), db_game.getSys_id() );
	}

	/**
	 * Tests that you can insert a game
	 * @Test
	 */
	public final void testInsertgame() {
		//inserting a game
		db.insertgame( "MegaMan", "/home/mike", 1, 1 );
		
		//making sure game is in database 
		List<Games> games = db.getAllGames();
		List<Games> expected = new ArrayList<Games>();
		
		expected.add( new Games( "MegaMan", 17, 1, "/home/mike", 1 ) );
		
		assertEquals( games.get( 0 ).getDev_id(), expected.get( 0 ).getDev_id() );
		assertEquals( games.get( 0 ).getGame_cover(), expected.get( 0 ).getGame_cover() );
		assertEquals( games.get( 0 ).getGame_id(), expected.get( 0 ).getGame_id() );
		assertEquals( games.get( 0 ).getGame_title(), expected.get( 0 ).getGame_title() );
		assertEquals( games.get( 0 ).getSys_id(), expected.get( 0 ).getSys_id() );
	}

	/**
	 * Tests that you can get a game by its game id
	 * @Test
	 */
	public final void testGetGameById() {
		//creating a game 
		Games game = db.creategame( "MegaMan", "/home/mike", 1, 1 );
		
		//making sure we can get the correct game back when we provide the game id
		Games db_game = db.getGameById( game.getGame_id() );
		assertEquals( game.getDev_id(), db_game.getDev_id() );
		assertEquals( game.getGame_cover(), db_game.getGame_cover() );
		assertEquals( game.getGame_id(), db_game.getGame_id() );
		assertEquals( game.getGame_title(), db_game.getGame_title() );
		assertEquals( game.getSys_id(), db_game.getSys_id() );
	}

	/**
	 * Tests that you can get all games in the database
	 * @Test
	 */
	public final void testGetAllGames() {
		//inserting some games
		db.insertgame( "MegaMan", "/home/mike", 1, 1 );
		db.insertgame( "Zelda", "/home/mike", 2, 2 );
		db.insertgame( "Mario", "/home/mike", 3, 3 );
		
		//making sure we can get all of the games 
		List<Games> games = db.getAllGames();
		List<Games> expected = new ArrayList<Games>();
		
		expected.add( new Games( "MegaMan", 3, 1, "/home/mike", 1 ) );
		expected.add( new Games( "Zelda", 4, 2, "/home/mike", 2 ) );
		expected.add( new Games( "Mario", 5, 3, "/home/mike", 3 ) );
		
		for( int i = 0; i < 3; i++ ) {
			assertEquals( games.get( i ).getDev_id(), expected.get( i ).getDev_id() );
			assertEquals( games.get( i ).getGame_cover(), expected.get( i ).getGame_cover() );
			assertEquals( games.get( i ).getGame_id(), expected.get( i ).getGame_id() );
			assertEquals( games.get( i ).getGame_title(), expected.get( i ).getGame_title() );
			assertEquals( games.get( i ).getSys_id(), expected.get( i ).getSys_id() );
		}
	}

	/**
	 * Tests that you can delete a system
	 * @Test
	 */
	public final void testDeleteSystem() {
		//creating a system
		Systems system = db.createSystem( "Super Nintendo", "home/mike", "nes", 1, 1 );
		
		int delete_id = system.getSys_id();
		
		//deleting the new system
		db.deleteSystem( delete_id );
		
		//making sure system is gone
		List<Systems> systems = db.getAllSystems();
		
		for (Systems temp_systems : systems) {
			Integer temp_id = temp_systems.getSys_id();
			assertFalse( temp_id.equals( delete_id ) );
		}
	}

	/**
	 * Tests that you can insert a system and get the inserted system back
	 * @Test
	 */
	public final void testCreateSystem() {
		//creating a system
		Systems system = db.createSystem( "Super Nintendo", "home/mike", "nes", 1, 1 );
		
		//making sure game is in system
		Systems db_system = db.getSystemById( system.getSys_id() );
		assertEquals( system.getSys_directory(), db_system.getSys_directory() );
		assertEquals( system.getSys_ext(), db_system.getSys_ext() );
		assertEquals( system.getSys_id(), db_system.getSys_id() );
		assertEquals( system.getSys_is_active(), db_system.getSys_is_active() );
		assertEquals( system.getSys_name(), db_system.getSys_name() );
		assertEquals( system.getTheme_id(), db_system.getTheme_id() );
	}

	/**
	 * Tests that you can insert a system
	 * @Test
	 */
	public final void testInsertSystem() {
		//inserting a system
		db.insertSystem( "Super Nintendo", "home/mike", "nes", 1, 1 );
		
		//making sure game is in system 
		List<Systems> systems = db.getAllSystems();
		List<Systems> expected = new ArrayList<Systems>();
		
		expected.add( new Systems( 15, "Super Nintendo", "home/mike", "nes", 1, 1 ) );
		
		assertEquals( systems.get( 0 ).getSys_directory(), expected.get( 0 ).getSys_directory() );
		assertEquals( systems.get( 0 ).getSys_ext(), expected.get( 0 ).getSys_ext() );
		assertEquals( systems.get( 0 ).getSys_id(), expected.get( 0 ).getSys_id() );
		assertEquals( systems.get( 0 ).getSys_is_active(), expected.get( 0 ).getSys_is_active() );
		assertEquals( systems.get( 0 ).getSys_name(), expected.get( 0 ).getSys_name() );
		assertEquals( systems.get( 0 ).getTheme_id(), expected.get( 0 ).getTheme_id() );
	}

	/**
	 * Tests that you can get a system by its system id
	 * @Test
	 */
	public final void testGetSystemById() {
		//creating a system 
		Systems system = db.createSystem( "Super Nintendo", "home/mike", "nes", 1, 1 );
		
		//making sure we can get the correct system back when we provide the system id
		Systems db_system = db.getSystemById( system.getSys_id() );
		assertEquals( system.getSys_directory(), db_system.getSys_directory() );
		assertEquals( system.getSys_ext(), db_system.getSys_ext() );
		assertEquals( system.getSys_id(), db_system.getSys_id() );
		assertEquals( system.getSys_is_active(), db_system.getSys_is_active() );
		assertEquals( system.getSys_name(), db_system.getSys_name() );
		assertEquals( system.getTheme_id(), db_system.getTheme_id() );
	}

	/**
	 * Tests that you can get all systems in the database
	 * @Test
	 */
	public final void testGetAllSystems() {
		//inserting some systems
		db.insertSystem( "Super Nintendo", "home/mike", "nes", 1, 1 );
		db.insertSystem( "Nintendo", "home/mike", "ns", 2, 2 );
		db.insertSystem( "GameBoy", "home/mike", "gb", 3, 3 );
		
		//making sure we can get all of the games 
		List<Systems> systems = db.getAllSystems();
		List<Systems> expected = new ArrayList<Systems>();
		
		expected.add( new Systems( 9, "Super Nintendo", "home/mike", "nes", 1, 1 ) );
		expected.add( new Systems( 10, "Nintendo", "home/mike", "ns", 2, 2 ) );
		expected.add( new Systems( 11, "GameBoy", "home/mike", "gb", 3, 3 ) );
		
		for( int i = 0 ; i < 3 ; i++ ) {
			assertEquals( systems.get( i ).getSys_directory(), expected.get( i ).getSys_directory() );
			assertEquals( systems.get( i ).getSys_ext(), expected.get( i ).getSys_ext() );
			assertEquals( systems.get( i ).getSys_id(), expected.get( i ).getSys_id() );
			assertEquals( systems.get( i ).getSys_is_active(), expected.get( i ).getSys_is_active() );
			assertEquals( systems.get( i ).getSys_name(), expected.get( i ).getSys_name() );
			assertEquals( systems.get( i ).getTheme_id(), expected.get( i ).getTheme_id() );
		}
	}

	/**
	 * Tests that you can delete a theme
	 * @Test
	 */
	public final void testDeletetheme() {
		//creating a theme
		Themes theme = db.createTheme( "blue", "red", "orange", "green" );
		
		int delete_id = theme.getTheme_id();
		
		//deleting the new theme
		db.deletetheme( delete_id );
		
		//making sure theme is gone
		List<Themes> themes = db.getAllThemes();
		
		for (Themes temp_themes : themes) {
			Integer temp_id = temp_themes.getTheme_id();
			assertFalse( temp_id.equals( delete_id ) );
		}
	}

	/**
	 * Tests that you can insert a theme and get the inserted theme back
	 * @Test
	 */
	public final void testCreateTheme() {
		//creating a theme
		Themes theme = db.createTheme( "blue", "red", "orange", "green" );
		
		//making sure theme is in database
		Themes db_theme = db.getThemeById( theme.getTheme_id() );
		assertEquals( theme.getTheme_background_main(), db_theme.getTheme_background_main() );
		assertEquals( theme.getTheme_background_table(), db_theme.getTheme_background_table() );
		assertEquals( theme.getTheme_id(), db_theme.getTheme_id() );
		assertEquals( theme.getTheme_text_primary(), db_theme.getTheme_text_primary() );
		assertEquals( theme.getTheme_text_secondary(), db_theme.getTheme_text_secondary() );
	}

	/**
	 * Tests that you can insert a theme
	 * @Test
	 */
	public final void testInsertTheme() {
		//inserting a theme
		db.insertTheme( "blue", "red", "orange", "green" );
		
		//making sure theme is in database 
		List<Themes> themes = db.getAllThemes();
		List<Themes> expected = new ArrayList<Themes>(); 
		
		expected.add( new Themes( 7, "blue", "red", "orange", "green" ) );

		assertEquals( themes.get( 0 ).getTheme_background_main(), expected.get( 0 ).getTheme_background_main() );
		assertEquals( themes.get( 0 ).getTheme_background_table(), expected.get( 0 ).getTheme_background_table() );
		assertEquals( themes.get( 0 ).getTheme_id(), expected.get( 0 ).getTheme_id() );
		assertEquals( themes.get( 0 ).getTheme_text_primary(), expected.get( 0 ).getTheme_text_primary() );
		assertEquals( themes.get( 0 ).getTheme_text_secondary(), expected.get( 0 ).getTheme_text_secondary() );
	}

	/**
	 * Tests that you can get a theme by its theme id
	 * @Test
	 */
	public final void testGetThemeById() {
		//creating a theme 
		Themes theme = db.createTheme( "blue", "red", "orange", "green" );
		
		//making sure we can get the correct theme back when we provide the theme id
		Themes db_theme = db.getThemeById( theme.getTheme_id() );
		assertEquals( theme.getTheme_background_main(), db_theme.getTheme_background_main() );
		assertEquals( theme.getTheme_background_table(), db_theme.getTheme_background_table() );
		assertEquals( theme.getTheme_id(), db_theme.getTheme_id() );
		assertEquals( theme.getTheme_text_primary(), db_theme.getTheme_text_primary() );
		assertEquals( theme.getTheme_text_secondary(), db_theme.getTheme_text_secondary() );
	}

	/**
	 * Tests that you can get all themes in the database
	 * @Test
	 */
	public final void testGetAllThemes() {
		//inserting some themes
		db.insertTheme( "blue", "red", "orange", "green" );
		db.insertTheme( "black", "green", "blue", "orange" );
		db.insertTheme( "yellow", "magenta", "cyan", "turquoise" );
		
		//making sure we can get all of the games 
		List<Themes> themes = db.getAllThemes();
		List<Themes> expected = new ArrayList<Themes>(); 
		
		expected.add( new Themes( 3, "blue", "red", "orange", "green" ) );
		expected.add( new Themes( 4, "black", "green", "blue", "orange" ) );
		expected.add( new Themes( 5, "yellow", "magenta", "cyan", "turquoise" ) );
		
		for( int i = 0 ; i < 3 ; i++ ) {
			assertEquals( themes.get( i ).getTheme_background_main(), expected.get( i ).getTheme_background_main() );
			assertEquals( themes.get( i ).getTheme_background_table(), expected.get( i ).getTheme_background_table() );
			assertEquals( themes.get( i ).getTheme_id(), expected.get( i ).getTheme_id() );
			assertEquals( themes.get( i ).getTheme_text_primary(), expected.get( i ).getTheme_text_primary() );
			assertEquals( themes.get( i ).getTheme_text_secondary(), expected.get( i ).getTheme_text_secondary() );
		}
	}

	/**
	 * Tests that you can get all games sorted by game title
	 * @Test
	 */
	public final void testGetGamesSortedByGameTitle() {
		//inserting some games
		db.insertgame( "MegaMan", "/home/mike", 1, 1 );
		db.insertgame( "Zelda", "/home/mike", 2, 2 );
		db.insertgame( "Mario", "/home/mike", 3, 3 );
		
		//making sure we can get all of the games sorted by game title 
		List<Games> games = db.getGamesSortedByGameTitle();
		List<Games> expected = new ArrayList<Games>();
		
		expected.add( new Games( "Mario", 15, 3, "/home/mike", 3 ) );
		expected.add( new Games( "MegaMan", 13, 1, "/home/mike", 1 ) );
		expected.add( new Games( "Zelda", 14, 2, "/home/mike", 2 ) );
		
		for( int i = 0; i < 3; i++ ) {
			assertEquals( games.get( i ).getDev_id(), expected.get( i ).getDev_id() );
			assertEquals( games.get( i ).getGame_cover(), expected.get( i ).getGame_cover() );
			assertEquals( games.get( i ).getGame_id(), expected.get( i ).getGame_id() );
			assertEquals( games.get( i ).getGame_title(), expected.get( i ).getGame_title() );
			assertEquals( games.get( i ).getSys_id(), expected.get( i ).getSys_id() );
		}	
	}

	/**
	 * Tests that you can get all saves for a particular game
	 * @Test
	 */
	public final void testGetSavesByGameID() {
		//inserting some saves for game id 1
		db.insertSave( 1, "MegaMan Save", "2013/11/29", "2013/11/29", "/home/mike", 1 );
		db.insertSave( 1, "Zelda Save", "2013/11/28", "2013/11/28", "/home/mike", 2 );
		db.insertSave( 1, "Mario Save", "2013/11/27", "2013/11/27", "/home/mike", 3 );
		
		//getting all saves for game with id 1 
		List<Saves> saves = db.getAllSaves();
		List<Saves> expected = new ArrayList<Saves>();
		
		expected.add( new Saves( 14, 1, "MegaMan Save", "2013/11/29", "2013/11/29", "/home/mike", 1 ) );
		expected.add( new Saves( 15, 1, "Zelda Save", "2013/11/28", "2013/11/28", "/home/mike", 2 ) );
		expected.add( new Saves( 16, 1, "Mario Save", "2013/11/27", "2013/11/27", "/home/mike", 3 ) );
		
		for( int i = 0 ; i < 3 ; i++ ) {
			assertEquals( saves.get( i ).getDev_id(), expected.get( i ).getDev_id() );
			assertEquals( saves.get( i ).getGame_id(), expected.get( i ).getGame_id() );
			assertEquals( saves.get( i ).getSave_date_created(), expected.get( i ).getSave_date_created() );
			assertEquals( saves.get( i ).getSave_date_logged(), expected.get( i ).getSave_date_logged() );
			assertEquals( saves.get( i ).getSave_descrip() , expected.get( i ).getSave_descrip() );
			assertEquals( saves.get( i ).getSave_id() , expected.get( i ).getSave_id() );
			assertEquals( saves.get( i ).getSave_src() , expected.get( i ).getSave_src() );
		}
	}

	/**
	 * Tests that you can get a game and the system info for the game
	 * @Test
	 */
	public final void testGetGamesOnSystem() {
		//inserting a system
		Systems system = db.createSystem( "Super Nintendo", "home/mike", "nes", 1, 1 );
		
		//inserting a game
		db.insertgame( "MegaMan", "/home/mike", 1, system.getSys_id() );
		db.insertgame( "Zelda", "/home/mike", 1, system.getSys_id() );
		db.insertgame( "Mario", "/home/mike", 1, system.getSys_id() );
		
		//getting all games for system with id 1 
		List<Games> games = db.getGamesOnSystem( system.getSys_id() );
		List<Games> expected = new ArrayList<Games>();
		
		expected.add( new Games( "MegaMan", 8, 1, "/home/mike", system.getSys_id() ) );
		expected.add( new Games( "Zelda", 9, 1, "/home/mike", system.getSys_id() ) );
		expected.add( new Games( "Mario", 10, 1, "/home/mike", system.getSys_id() ) );
		
		for( int i = 0; i < 3; i++ ) {
			assertEquals( games.get( i ).getDev_id(), expected.get( i ).getDev_id() );
			assertEquals( games.get( i ).getGame_cover(), expected.get( i ).getGame_cover() );
			assertEquals( games.get( i ).getGame_id(), expected.get( i ).getGame_id() );
			assertEquals( games.get( i ).getGame_title(), expected.get( i ).getGame_title() );
			assertEquals( games.get( i ).getSys_id(), expected.get( i ).getSys_id() );
		}
	}
	
	/**
	 * Tests that you can get the latest save for a game
	 * @Test
	 */
	public final void testGetLatestSaveForGame() {
		//inserting a game
		db.insertgame( "MegaMan", "/home/mike", 1, 1 );
		
		//insert some saves
		db.insertSave( 1, "MegaMan Save", "2013/11/29", "2013/11/29", "/home/mike", 1 );
		db.insertSave( 1, "MegaMan Save", "2013/11/28", "2013/11/28", "/home/mike", 2 );
		db.insertSave( 1, "MegaMan Save", "2013/11/27", "2013/11/27", "/home/mike", 3 );
		
		//getting the latest  save information 
		Saves save = db.getLatestSaveForGame( 1 );
		Saves expected = new Saves( 10, 1, "MegaMan Save", "2013/11/29", "2013/11/29", "/home/mike", 1 );
		
		assertEquals( save.getDev_id(), expected.getDev_id() );
		assertEquals( save.getGame_id(), expected.getGame_id() );
		assertEquals( save.getSave_date_created(), expected.getSave_date_created() );
		assertEquals( save.getSave_date_logged(), expected.getSave_date_logged() );
		assertEquals( save.getSave_descrip() , expected.getSave_descrip() );
		assertEquals( save.getSave_id() , expected.getSave_id() );
		assertEquals( save.getSave_src() , expected.getSave_src() );
	}

	/**
	 * Tests that updateSystemSource will update the system with the new system source path
	 * @Test
	 */
	public final void testUpdateSystemSource() {
		//inserting a system
		Systems system = db.createSystem( "Super Nintendo", "home/mike", "nes", 1, 1 );

		db.updateSystemSource( "home/mike/backup", system.getSys_id() );
		
		Systems new_system = db.getSystemById( system.getSys_id() );
		
		assertEquals( "home/mike/backup", new_system.getSys_directory() );
	}
	
	/**
	 * Tests that getGameByTitle will return the game that has the provided title
	 * @Test
	 */
	public final void testGetGameByTitle() {
		//inserting a game
		Games game = db.creategame( "MegaMan", "/home/mike", 1, 1 );
		
		//getting the game by title
		Games game_by_title = db.getGameByTitle( game.getGame_title() );
		
		//making sure we got the correct game back
		assertEquals( game.getDev_id(), game_by_title.getDev_id() );
		assertEquals( game.getGame_cover(), game_by_title.getGame_cover() );
		assertEquals( game.getGame_id(), game_by_title.getGame_id() );
		assertEquals( game.getGame_title(), game_by_title.getGame_title() );
		assertEquals( game.getSys_id(), game_by_title.getSys_id() );
	}
	
	/**
	 * Tests that saveDateCreatedExists will correctly identify if a save exists that has the provided date
	 * @Test
	 */
	public final void testSaveDateCreatedExists() {
		//insert a save
		db.createSave( 1, "MegaMan Save", "2013/11/29", "2013/11/29", "/home/mike", 1 );
		
		//making sure we can check if a save has a date
		assertTrue( db.saveDateCreatedExists( "2013/11/29" ) );
		assertFalse( db.saveDateCreatedExists( "2013/11/28" ) );
	}
	
	/**
	 * Tests that updateSaveDateCreated will correctly update the save date created for the save with the provided id
	 * @Test
	 */
	public final void testUpdateSaveDateCreated() {
		//insert a save
		Saves save = db.createSave( 1, "MegaMan Save", "2013/11/29", "2013/11/29", "/home/mike", 1 );
				
		//updating the save date created
		db.updateSaveDateCreated( "2013/11/28", save.getSave_id() );
		
		//getting the save again
		Saves updated_save = db.getSaveById( save.getSave_id() );
		
		assertEquals( "2013/11/28", updated_save.getSave_date_created() );
	}
	
	/**
	 * Tests that you can get all games for a system sorted by game title
	 */
	public final void testGetGamesOnSystemAZ() {
		//inserting a system
		Systems system = db.createSystem( "Super Nintendo", "home/mike", "nes", 1, 1 );
		
		//inserting some games
		Games game_2 = db.creategame( "Zelda", "/home/mike", 1, system.getSys_id() );
		Games game_1 = db.creategame( "MegaMan", "/home/mike", 1, system.getSys_id() );
		
		//inserting some saves for the games
		Saves save_1 = db.createSave( game_1.getGame_id(), "MegaMan Save 1", "2013/11/29", "2013/11/29", "/home/mike", 1 );
		Saves save_2 = db.createSave( game_1.getGame_id(), "MegaMan Save 2", "2013/11/25","2013/11/29", "/home/mike", 1 );
		Saves save_3 = db.createSave( game_2.getGame_id(), "Zelda Save 1", "2013/11/20", "2013/11/29", "/home/mike", 1 );
		Saves save_4 = db.createSave( game_2.getGame_id(), "Zelda Save 2", "2013/11/30", "2013/11/29", "/home/mike", 1 );
		
		//getting games for system with provided id sorted az
		List<Games> games = db.getGamesOnSystemAZ( system.getSys_id() );
		
		assertEquals( games.get( 0 ).getDev_id(), game_1.getDev_id() );
		assertEquals( games.get( 0 ).getGame_cover(), game_1.getGame_cover() );
		assertEquals( games.get( 0 ).getGame_id(), game_1.getGame_id() );
		assertEquals( games.get( 0 ).getGame_title(), game_1.getGame_title() );
		assertEquals( games.get( 0 ).getSys_id(), game_1.getSys_id() );
		
		assertEquals( games.get( 1 ).getDev_id(), game_2.getDev_id() );
		assertEquals( games.get( 1 ).getGame_cover(), game_2.getGame_cover() );
		assertEquals( games.get( 1 ).getGame_id(), game_2.getGame_id() );
		assertEquals( games.get( 1 ).getGame_title(), game_2.getGame_title() );
		assertEquals( games.get( 1 ).getSys_id(), game_2.getSys_id() );
	}

}
